<template>
    <div class="navigate">
        <div>
        <el-radio-group v-model="isCollapse" style="margin-bottom: 20px;">
        <el-radio-button :value="false">expand</el-radio-button>
        <el-radio-button :value="true">collapse</el-radio-button>
        </el-radio-group>
    </div>
    <el-menu :default-active="activeIndex" 
        mode="horizontal"
        class="el-menu-vertical-demo"
        :collapse="isCollapse"
        @open="handleOpen"
        @close="handleClose"
        router >
    <el-menu-item index="1">
        <el-icon><icon-menu /></el-icon>
        <template #title>首页</template>
    </el-menu-item>
    <el-menu-item index="2">
    <el-icon><icon-menu /></el-icon>
        <template #title>餐厅详情页</template>
    </el-menu-item>
    <el-menu-item index="3">
        <el-icon><document /></el-icon>
        <template #title>用户信息页</template>
    </el-menu-item>
  </el-menu>
    </div>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue';
import { useRoute } from 'vue-router/types/composables.js';
  const isCollapse=ref(true)
  const handleOpen=(key:string,keyPath: string[])=>{
    console.log(key,keyPath)
  }
  const handleClose=(key: string,keyPath:string[])=>{
    console.log(key,keyPath)
  }
const route=useRoute();
const activeIndex=ref(route.path);// 使用 ref 来创建响应式数据

//使用watch来监听路由变化
watch(route, (to, from)=> {
    activeIndex.value = to.path;
});
</script>

<style scoped>
</style>